using System;
using Oracle.ManagedDataAccess.Types;
using OracleInternal.Json.Binary;

namespace OracleInternal.Json.Sql
{
	internal class OracleJsonDecimal : OracleJsonNumber
	{
		internal static string NEGATIVE_INF = "\"-Inf\"";

		internal static string POSITIVE_INF = "\"Inf\"";

		private byte[] m_raw;

		private TargetType m_targetType = TargetType.DECIMAL;

		internal OracleJsonDecimal()
		{
		}

		internal OracleJsonDecimal(decimal value)
		{
			m_raw = OsonPrimitiveConversions.ToNumber(value);
		}

		internal OracleJsonDecimal(long value)
		{
			m_raw = OsonPrimitiveConversions.ToNumber(value);
			m_targetType = TargetType.LONG;
		}

		internal OracleJsonDecimal(int value)
		{
			m_raw = OsonPrimitiveConversions.ToNumber(value);
			m_targetType = TargetType.INT;
		}

		internal OracleJsonDecimal(byte[] raw, TargetType type)
		{
			if (raw.Length == 22)
			{
				int num = raw[0];
				m_raw = new byte[num];
				Array.Copy(raw, 1, m_raw, 0, num);
			}
			else
			{
				m_raw = raw;
			}
			m_targetType = type;
		}

		public override OracleJsonType GetOracleJsonType()
		{
			return OracleJsonType.DECIMAL;
		}

		internal void Reset(byte[] raw, TargetType type)
		{
			m_raw = raw;
			m_targetType = type;
		}

		internal override decimal BigDecimalValue()
		{
			return OsonPrimitiveConversions.ToBigDecimal(m_raw);
		}

		internal byte[] Raw()
		{
			return m_raw;
		}

		internal override string GetJsonString()
		{
			int num = m_raw.Length;
			if (num <= 2)
			{
				if (OsonPrimitiveConversions.IsNegInf(m_raw, num, 0))
				{
					return NEGATIVE_INF;
				}
				if (OsonPrimitiveConversions.IsPosInf(m_raw))
				{
					return POSITIVE_INF;
				}
			}
			return DecimalConv.ToString(m_raw);
		}

		internal bool IsDec()
		{
			return m_targetType == TargetType.DECIMAL;
		}

		internal bool IsSB4()
		{
			return m_targetType == TargetType.INT;
		}

		internal bool IsSB8()
		{
			return m_targetType == TargetType.LONG;
		}

		internal virtual TargetType GetTargetType()
		{
			return m_targetType;
		}
	}
}
